<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="业务类型">
              <!--              <a-input placeholder="请输入分类名称" v-model="queryParam.name"></a-input>-->
<!--              <j-dict-select-tag type="list" v-model="queryParam.businessType"-->
<!--                                 dictCode="business_type" placeholder="请选择业务类型"/>-->
                  <j-dict-select-tag ref="dictSelect" type="list" v-model="queryParam.businessType"
                                      placeholder="请选择业务类型"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('成品入库单')">导出</a-button>
<!--      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">-->
<!--        <a-button type="primary" icon="import">导入</a-button>-->
<!--      </a-upload>-->
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        <a-popover title="自定义列" trigger="click" placement="leftBottom" style="float: right">
          <template slot="content">
            <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
              <a-row>
                <template v-for="(item,index) in defColumns">
                  <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                    <a-col :span="12"><a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox></a-col>
                  </template>
                </template>
              </a-row>
            </a-checkbox-group>
          </template>
          <a><a-icon type="setting" />自定义列</a>
        </a-popover>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :scroll="{x:true}"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>
    <buss-product-storage-modal ref="modalForm" @ok="modalFormOk"/>
  </a-card>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import BussProductStorageModal from './modules/BussProductStorageModal'
  import '@/assets/less/TableExpand.less'

  export default {
    name: "BussProductStorageList",
    mixins:[JeecgListMixin],
    components: {
      BussProductStorageModal
    },
    data () {
      return {
        description: '成品入库单管理页面',
        // 表头
        columns: [],
        settingColumns: [],
        // 表头
        defColumns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'单号',
            align:"center",
            dataIndex: 'code',
            customRender:  (text, record, index) => {
              const obj = {
                children: [<span>{text}</span>],
                attrs: {},
              };
              // 判断是否需要合并行
              if (index > 0 && record.id === this.dataSource[index - 1].id) {
                obj.attrs.rowSpan = 0;
              } else {
                obj.attrs.rowSpan = this.dataSource.filter(item => item.id === record.id).length;
              }
              return obj;
            }
          },
          // {
          //   title:'业务节点',
          //   align:"center",
          //   dataIndex: 'businessNode_dictText'
          // },
          // {
          //   title:'物料大类',
          //   align:"center",
          //   dataIndex: 'materialTypeName'
          // },
          {
            title:'业务类型',
            align:"center",
            dataIndex: 'businessType_dictText'
          },
          {
            title:'仓库',
            align:"center",
            dataIndex: 'warehouseId'
          },
          {
            title:'物料编号',
            align:"center",
            dataIndex: 'materialCode'
          },
          {
            title:'客户物料编号',
            align:"center",
            dataIndex: 'customerMaterialCode'
          },
          {
            title:'物料名称',
            align:"center",
            dataIndex: 'materialName'
          },
          {
            title:'物料规格',
            align:"center",
            dataIndex: 'noneSpec'
          },
          {
            title:'计量单位',
            align:"center",
            dataIndex: 'unit'
          },
          {
            title:'入库数量',
            align:"center",
            dataIndex: 'num'
          },
          {
            title:'辅助单位',
            align:"center",
            dataIndex: 'supportUnit'
          },
          {
            title:'辅助数量',
            align:"center",
            dataIndex: 'supportNum'
          },
          {
            title:'上级单号',
            align:"center",
            dataIndex: 'superiorCode'
          },
          {
            title:'经办人员',
            align:"center",
            dataIndex: 'handlingPersonnel'
          },
          {
            title:'制单日期',
            align:"center",
            dataIndex: 'createTime'
          },
          {
            title:'制单人',
            align:"center",
            dataIndex: 'createBy'
          },
          {
            title:'制单部门',
            align:"center",
            dataIndex: 'sysOrgCode'
          },
          {
            title:'入库日期',
            align:"center",
            dataIndex: 'storageDate',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'生产车间',
            align:"center",
            dataIndex: 'workshop'
          },
          {
            title:'客户名称',
            align:"center",
            dataIndex: ''
          },
          {
            title:'批次号',
            align:"center",
            dataIndex: 'lotNumber'
          },
          {
            title:'备注',
            align:"center",
            dataIndex: 'remark'
          },
          {
            title:'限用日期',
            align:"center",
            dataIndex: 'expiredDate',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'生产日期',
            align:"center",
            dataIndex: 'createDate',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'质检状态',
            align:"center",
            dataIndex: 'detailStatus'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            customRender:  (text, record, index) => {
              const obj = {
                children: [
                   record.status === 0  && (
                    <a onClick={() => this.handleEdit(record)}>编辑</a>
                  ),
                  record.status === 0  && (
                    <a-divider type='vertical'></a-divider>
                  ),
                  <a-dropdown>
                    <a class='ant-dropdown-link'>更多 <a-icon type='down' /></a>
                    <a-menu slot="overlay">
                      <a-menu-item>
                        <a onClick={() => this.handleDetail(record)}>详情</a>
                      </a-menu-item>
                      <a-menu-item>
                        <a-popconfirm title='确定删除吗?' onConfirm={() => this.handleDelete(record.id)}>
                          <a>删除</a>
                        </a-popconfirm>
                      </a-menu-item>
                    </a-menu>
                  </a-dropdown>
                ],
                attrs: {},
              };
              // 判断是否需要合并行
              if (index > 0 && record.id === this.dataSource[index - 1].id) {
                obj.attrs.rowSpan = 0;
              } else {
                obj.attrs.rowSpan = this.dataSource.filter(item => item.id === record.id).length;
              }
              return obj;
            }
            // scopedSlots: { customRender: 'action' },
          }
        ],
        url: {
          list: "/business/bussProductStorage/page",
          delete: "/business/bussProductStorage/delete",
          deleteBatch: "/business/bussProductStorage/deleteBatch",
          exportXlsUrl: "/business/bussProductStorage/exportXls",
          importExcelUrl: "business/bussProductStorage/importExcel",

        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
      this.getSuperFieldList();
      this.initColumns();
    },
    mounted() {
      //dictSelect
      this.$refs.dictSelect.setCurrentDictOptions([
        {label:'成品入库',value:'4'},
        {label:'发出商品通知赤字入库',value:'5'},
        {label:'小组作业入库',value:'6'},
      ])
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'code',text:'单号',dictCode:''})
        fieldList.push({type:'string',value:'businessNode',text:'业务节点',dictCode:''})
        fieldList.push({type:'string',value:'materialTypeName',text:'物料大类',dictCode:''})
        fieldList.push({type:'string',value:'materialTypeCode',text:'物料大类',dictCode:''})
        fieldList.push({type:'string',value:'businessType',text:'业务类型',dictCode:''})
        fieldList.push({type:'string',value:'warehouseId',text:'仓库',dictCode:''})
        fieldList.push({type:'string',value:'superiorCode',text:'上级单号',dictCode:''})
        fieldList.push({type:'date',value:'storageDate',text:'入库日期'})
        fieldList.push({type:'string',value:'handlingPersonnelId',text:'经办人员',dictCode:''})
        fieldList.push({type:'string',value:'handlingPersonnel',text:'经办人员',dictCode:''})
        fieldList.push({type:'string',value:'lotNumber',text:'批次号',dictCode:''})
        fieldList.push({type:'string',value:'workshop',text:'生产车间',dictCode:''})
        fieldList.push({type:'string',value:'logtime',text:'日志时间',dictCode:''})
        fieldList.push({type:'int',value:'status',text:'状态',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>